package cn.chenxiejia;

import java.util.ArrayList;
import java.util.List;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: Hanshujie
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/1/26 9:37
 */
public class Hanshujie {
    public static void main(String[] args) {
        List<User> list = new ArrayList<>(List.of(
                new User(1, 23, "张三"),
                new User(2, 20, "张永"),
                new User(3, 18, "张力"),
                new User(4, 28, "李四"),
                new User(5, 15, "王五")));
        //filter筛选器，limit限制数量
        list.stream().filter(a -> a.getAge() > 20).forEach(System.out::println);
        System.out.println();
        list.stream().filter(a -> a.getId() > 2).forEach(System.out::println);
        System.out.println();
        list.stream().filter(a -> a.getName().startsWith("张")).forEach(System.out::println);
        System.out.println();
        //map给出一个参数返回一个参数
        list.stream().filter(a -> a.getName().startsWith("张")).map(a -> {
                    a.setAge(a.getAge() + 2);
                    return a;
                }
        ).forEach(System.out::println);
        list.sort((a, b) -> a.getAge() - b.getAge());


    }
}
